<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>日志记录</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="7">
          <el-input placeholder="请输入内容" v-model="query" clearable>
            <el-button slot="append" @click="serch" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" icon="el-icon-loading" @click="shuaxin">刷新</el-button>
        </el-col>
      </el-row>
      <el-table
          :data="tableData"
          stripe
          border
          style="width: 100%">
        <el-table-column
            fixed
            prop="operId"
            label="id"
            width="50"
        >
        </el-table-column>
        <el-table-column
            prop="title"
            label="日志名称"
        >
        </el-table-column>
        <el-table-column
            prop="method"
            label="操作方法"
            show-overflow-tooltip
        >
        </el-table-column>

        <el-table-column
            prop="operUrl"
            label="操作接口"
            show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
            prop="operParam"
            label="参数"
            show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
            prop="status"
            label="状态">
          <template slot-scope="scope">
            <el-switch
                disabled
                v-model="scope.row.status"
                :active-value="0"
                :inactive-value="1"
                active-color="#13ce66"
                inactive-color="#ff4949">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column
            prop="operIp"
            label="IP地址"
        >
        </el-table-column>
        <el-table-column
            prop="operLocation"
            label="IP类型"
        >
        </el-table-column>
        <el-table-column
            prop="operName"
            label="操作人"
        >
        </el-table-column>
        <el-table-column
            prop="operTime"
            label="记录时间"
        >
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="160">
          <template slot-scope="scope">
            <el-button type="danger" icon="el-icon-delete" @click="DeleteRole(scope.row)"  size="medium" circle></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "operLog",
  data(){
    return{
      //查询条件
      query:"",
      //当前页码
      currentPage: 1,
      //每页显示记录
      pageSize:5,
      //总条数
      total:0,
      //当前的记录数据
      tableData: [],

    }
  },
  //页面加载自动执行
  created() {
    this.initOperLogTable(this.currentPage,this.pageSize);
  },
  methods: {
    //修改每页几条的方法
    handleSizeChange(val) {
      this.pageSize=val;
      this.initOperLogTable(this.currentPage,this.pageSize);
    },
    //修改页数的方法
    handleCurrentChange(val) {
      this.currentPage=val;
      this.initOperLogTable(this.currentPage,this.pageSize);
    },
    //模糊查询按钮的方法
    serch(){
      this.initOperLogTable(this.currentPage,this.pageSize);
    },
    //初始化表格的方法
    initOperLogTable(currentPage,pageSize){
      var that = this;
      this.$http.post(`/sys/operLog/findOperLogByPage/${currentPage}/${pageSize}?query=${this.query}`).then(function (res){
        if (res.data.code==200){
          that.tableData=res.data.data.records;
          that.total=res.data.data.total;
        }else{
          that.$message.error("用户信息加载失败");
        }
      })
    },
    //删除日志信息
    DeleteRole(row){
      var that=this;
      this.$confirm('是否删除用户:'+row.roleName+'?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        that.$http.get(`/sys/operLog/deleteMenuById/${row.operId}`).then(function(res){
          if (res.data.code == 200){
            if (that.total%that.pageSize==1){
              that.currentPage--;
            }else {
              that.currentPage = that.currentPage;
            }
            that.$message.success(res.data.msg);
            that.initOperLogTable(that.currentPage,that.pageSize);
          }else {
            that.$message.error(res.data.msg);
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //刷新页面
    shuaxin(){
      this.query = "";
      this.initOperLogTable(this.currentPage,this.pageSize);
    }

  }
}
</script>

<style scoped>

</style>